# -*- coding: utf-8 -*- 

'''
Created on 2018年8月30日

@author: Dergen Lee

'''

import numpy as np
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense,Dropout
from builtins import int
import matplotlib.pyplot as plt

# Generate dummy data
x_train=np.random.normal(0,1,size=(100000,20))
x_train=np.concatenate((x_train,np.random.normal(2,1,size=(100000,20))),axis=0)
y_labels=np.ones((100000,), dtype=int)
y_labels=np.concatenate((y_labels,np.zeros((100000,),dtype=int)),axis=0)

x_test=np.random.normal(0,1,size=(10000,20))
x_test=np.concatenate((x_test,np.random.normal(2,1,size=(10000,20))),axis=0)
y_test=np.ones((10000,), dtype=int)
y_test=np.concatenate((y_test,np.zeros((10000,),dtype=int)),axis=0)

model=Sequential()
model.add(Dense(64,input_dim=20,activation="relu"))
#model.add(Dropout(0.5))
model.add(Dense(64,activation="relu"))
#model.add(Dropout(0.5))
model.add(Dense(1,activation="sigmoid"))

model.compile(optimizer="rmsprop", 
              loss="binary_crossentropy", 
              metrics=["accuracy"])

history=model.fit(x_train, y_labels, 
          batch_size=12800, 
          epochs=20, 
          verbose=1)

score = model.evaluate(x_test, y_test, batch_size=12800)

print (score)

def plot_history(history):
    plt.figure(figsize=(16, 10))
    
    acc = history.history['acc']
    loss = history.history['loss']
    
    epochs = range(1, len(acc) + 1)
    
    # "bo" is for "blue dot"
    plt.plot(epochs, loss, 'bo', label='Training loss')
    
    # b is for "solid blue line"
    plt.plot(epochs, acc, 'b', label='Training accuracy')
    plt.title('Training loss and accuracy')
    plt.xlabel('Epochs')
    plt.ylabel('Loss')
    plt.legend()

plot_history(history)
plt.show()

